package com.srd.phone.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shengrongdai.srd.R;
import com.srd.phone.bean.Trecords;
import com.srd.phone.utils.views.ViewHolder;

import java.util.ArrayList;
import java.util.List;

public class InvestRecordAdapter extends BaseAdapter {

    private Context context;
    private List<Trecords> list = new ArrayList<Trecords>(10);

    public InvestRecordAdapter(Context context, List<Trecords> list0) {
        this.context = context;
        this.list = list0;
    }

    public void setData(List<Trecords> list0) {
        list = list0;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Trecords getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder viewHolder =  ViewHolder.get(context, view, parent, R.layout.item_invest_record, position);

        LinearLayout ll_layout = viewHolder.getView(R.id.ll_layout);
        if(position % 2 == 0)
            ll_layout.setBackgroundColor(Color.WHITE);
        else
            ll_layout.setBackgroundColor(Color.parseColor("#F7F7F7"));

        Trecords item = getItem(position);
        TextView tv_title_name = viewHolder.getView(R.id.tv_title_name);
        tv_title_name.setText(item.nm);
        TextView tv_date = viewHolder.getView(R.id.tv_date);
        tv_date.setText(item.stime);
        TextView tv_price = viewHolder.getView(R.id.tv_price);
        tv_price.setText(item.moneys + "元");
        TextView tv_numbers = viewHolder.getView(R.id.tv_numbers);
        tv_numbers.setText(item.numbersm);
        TextView tv_state = viewHolder.getView(R.id.tv_state);
        tv_state.setText(item.statm);
        switch (item.stat){
            case 57:
                tv_state.setTextColor(Color.parseColor("#FCC376"));
                tv_state.setBackgroundResource(R.drawable.shape_state_border_yellow);
                break;
            case 56:
            case 54:
                tv_state.setTextColor(Color.parseColor("#D6433F"));
                tv_state.setBackgroundResource(R.drawable.shape_state_border_red);
                break;
        }
        return viewHolder.getConvertView();
    }
}
